from django.urls import path
from . import views
from taggit.models import Tag
def post_list(request, tag_slug=None):
    posts = Post.published.all()
 # 创建变量tag，用于存储下方代码获取的标签
    tag = None
 # 如果请求中有tag_slug，则获取标签并按标签过滤文章数据
    if tag_slug:
 # 获取标签
        tag = get_object_or_404(Tag, slug=tag_slug)
 # 按标签过滤文章
        posts = posts.filter(tags=tag)
app_name = 'blog'

urlpatterns = [
 path('', views.post_list, name='post_list'),
 path('<int:year>/<int:month>/<int:day>/<slug:post>/', views.post_detail,
name='post_detail'),
 path('tag/<slug:tag_slug>/', views.post_list, name='post_list_by_tag'),
 path('<int:post_id>/share/', views.post_share, name='post_share'),
 path('search/', views.post_search, name='post_search') 
]
